/**
 * @表单验证
 */
import {
	toast
} from "./utils.js";
let verify = {
	verifyEmpty: function(...args){
		return new Promise(resolve=>{
			let empty = args.some(d => {
				if(typeof d === "object"){  // 如果有数组 检验 数组
					return d.length <= 0;
				}
				return d === "";
			})
			
			if(empty){
				toast({
					title: "必填项不能为空",
					icon: "none"
				})
			}
			resolve(empty)
		})
	},
	verifyPhone: function(phoneNum) {
		return new Promise(resolve=>{
			let isPhone = !(/^1[3456789]\d{9}$/.test(phoneNum));
			// if (isPhone) {
			// 	toast({
			// 		title: "手机号格式错误",
			// 		icon: "none"
			// 	});
			// }
			resolve(isPhone)
		})
	},
	verifyTelephone: function(phoneNum){
		return new Promise(resolve=>{
			let istelephone = !(/^(0[1-9]\d{1,2}-)\d{6,7}$/.test(phoneNum));
			// if(istelephone){
			// 	toast({
			// 		title: "座机号格式错误",
			// 		icon: "none"
			// 	});
			// }
			resolve(istelephone)
		})
	},
	verifyQQ: function(QQNum){
		return new Promise(resolve=>{
			let isQQ = !(/^[1-9][0-9]{4,14}$/.test(QQNum));
			if (isQQ) {
				toast({
					title: "QQ号格式错误",
					icon: "none"
				});
			}
			resolve(isQQ)
		})
	},
	verifyEmail: function(email) {
		return new Promise(resolve=>{
			let isEmail = !(/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(email));
			if (isEmail) {
				toast({
					title: "邮箱格式错误",
					icon: "none"
				});
			}
			resolve(isEmail)
		})
	},
	verifyPass: function(pass){
		return new Promise(resolve=>{
			let isPass = !(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}$/.test(pass));
			if (isPass) {
				toast({
					title: "密码格式为(必须包含大小写字母和数字的组合，不能使用特殊字符，长度在8-10之间)",
					icon: "none",
					duration:3000
				});
			}
			resolve(isPass)
		})
	},
	verifyURL: function(url){
		return new Promise(resolve=>{
			var strRegex = '^((https|http|ftp|rtsp|mms)?://)'
			+ '?(([0-9a-z_!~*\'().&=+$%-]+: )?[0-9a-z_!~*\'().&=+$%-]+@)?' //ftp的user@ 
			+ '(([0-9]{1,3}.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184 
			+ '|' // 允许IP和DOMAIN（域名） 
			+ '([0-9a-z_!~*\'()-]+.)*' // 域名- www. 
			+ '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' // 二级域名 
			+ '[a-z]{2,6})' // first level domain- .com or .museum 
			+ '(:[0-9]{1,4})?' // 端口- :80 
			+ '((/?)|' // a slash isn't required if there is no file name 
			+ '(/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+/?)$'; 
			var reg=new RegExp(strRegex); 
			let isUrl = !reg.test(url);
			
			if(isUrl){
				toast({
					title: "链接格式错误",
					icon: "none"
				});
			}
			
			resolve(isUrl)
		})
	}
}

export {
	verify
}
